const KoaRouter = require("@koa/router");
const {
  handleSingleFile,
  handleFileArray,
  handleSavePath,
} = require("../middleware/file.middleware.js");
const {
  singleFileUpdate,
  fileArrayUpdate,
} = require("../controller/file.controller");
const { verifyAuth } = require("../middleware/authority.middleware.js");

// 1. 创建路由对象
const fileRouter = new KoaRouter({ prefix: "/file" });

// 2. 定义路由中的映射
// 2.1 传头像
// 单文件
fileRouter.post(
  "/singleFile",
  verifyAuth,
  handleSavePath,
  handleSingleFile,
  singleFileUpdate
);
// 多文件
fileRouter.post(
  "/fileArray",
  verifyAuth,
  handleSavePath,
  handleFileArray,
  fileArrayUpdate
);

module.exports = fileRouter;
